package club.caihappy.controller;

import club.caihappy.domain.ResponseResult;
import club.caihappy.domain.entity.User;
import club.caihappy.enums.AppHttpCodeEnum;
import club.caihappy.handler.exception.SystemException;
import club.caihappy.service.BlogLoginService;
import io.jsonwebtoken.lang.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by DELL on 2022/11/2
 **/
@RestController
@RequestMapping("")
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;

    @GetMapping("login")
    public ResponseResult login(@RequestBody User user) {
        if (!Strings.hasText(user.getUserName())) {
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }


    @PostMapping("logout")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }
}
